#include<iostream>  
using namespace std;  
  
class CircularQueue {  
private:  
    int front, rear, size, queue[MAX];  
public:  
    CircularQueue(int s) {  
        front = rear = -1;  
        size = s;  
        for(int i=0; i<size; i++)  
            queue[i] = 0;  
    }  
    bool isFull() {  
        if((rear + 1) % size == front) return true;  
        return false;  
    }  
    bool isEmpty() {  
        if(front == -1) return true;  
        return false;  
    }  
    void enqueue(int val) {  
        if(isFull()) {  
            cout << "Queue is full. Cannot enqueue." << endl;  
            return;  
        }  
        if(front == -1) front = 0;  
        rear = (rear + 1) % size;  
        queue[rear] = val;  
    }  
    int dequeue() {  
        if(isEmpty()) {  
            cout << "Queue is empty. Cannot dequeue." << endl;  
            return -1; //返回-1表示出队失败  
        }  
        int val = queue[front];  
        if(front == rear) { //如果队列中只有一个元素  
            front = rear = -1; //重置front和rear  
        } else {  
            front = (front + 1) % size; //移动front指针  
        }  
        return val;  
    }  
    void display() { //打印队列中的元素  
        if(isEmpty()) {  
            cout << "Queue is empty." << endl;  
            return;  
        }  
        int i = front;  
        while(i != rear) {  
            cout << queue[i] << " ";  
            i = (i + 1) % size; //移动i指针，避免越界  
        }  
        cout << queue[rear] << endl; //打印最后一个元素，因为循环队列的最后一个元素被rear指向  
    }  
};